
<fieldset>
    <legend>Class Photo</legend>
    <div class="row">
        <?php
        $this->widget('xupload.XUpload', array(
            'url' => Yii::app()->createUrl("classes/upload"),
            'model' => $photos,
            'htmlOptions' => array('id' => 'classes-form'),
            'attribute' => 'file',
            'multiple' => true,
            'showForm' => false,
                )
        );
        ?>

        <div>
            <?php
            if (isset($_GET['id'])) {
                $classWithImage = Classes::getclassWithImage($_GET['id']);
                $dataProvider = new CArrayDataProvider($classWithImage, array(
                    'id' => 'classimage',
                    'sort' => array(
                        'attributes' => array(
                            'id', 'photo', 'class_id',),
                    ),
                    'pagination' => array(
                        'pageSize' => 10,),));


                $this->widget('zii.widgets.grid.CGridView', array(
                    'id' => 'classimage-grid',
                    'dataProvider' => $dataProvider,
                    'columns' => array(
                        array(
                            'name' => 'Image',
                            'type' => 'image',
                            'value' => 'Classes::classImageingridView($data)',
                            'htmlOptions' => array('style' => 'text-align: center'),
                        ),
                        array(
                            'name' => 'Primary image',
                            'type' => 'raw',
                            'value' => 'Classes::changeStatusIngridView($data)',
                            'filter' => array('0' => Yii::t('app', 'Inactive'), '1' => Yii::t('app', 'Active')),
                            'htmlOptions' => array('style' => 'text-align: center;padding:5px;'),
                        ),
                        array(
                            'id' => 'autoId',
                            'header' => 'Delete Image',
                            'class' => 'CCheckBoxColumn',
                            'selectableRows' => '50',
                            'checkBoxHtmlOptions' => array('name' => 'idList[]', 'onclick' => 'deleteAllRecord()', 'class' => 'deleteAllRecord'),
                        ),
                    ),
                ));
                $count = count($classWithImage) == '0' ? '' : count($classWithImage);
                echo '<input type="hidden" name="imagevalidation"  id="imagevalidation" value="' . $count . '">';
                echo '<input type="hidden" name="addimagevalidation"  id="addimagevalidation" value="' . $count . '">';
            } else {
                echo '<input type="hidden" name="imagevalidation" id="imagevalidation" >';
                echo '<input type="hidden" name="addimagevalidation" id="addimagevalidation" >';
            }
            ?>

        </div>
    </div>

</fieldset> 
<script type="text/javascript">
    function ChangeStatus(id, classid) {
        if (confirm("Are you sure for make this primary photo?")) {
            $.post("<?php echo Yii::app()->createUrl("classes/primaryImage"); ?>", {id: id, classid: classid}, function(result) {
                $('#classimage-grid').yiiGridView.update('classimage-grid');
            });
        }
    }

    function deleteAllRecord() {
        var idList = $(".deleteAllRecord:checked").serialize();
        if (idList) {
            if (confirm("Are you sure want to delete?")) {
                $.post("<?php echo Yii::app()->createUrl("classes/deleteClassImage"); ?>", idList, function(response) {
                    location.reload('#classImage-id');
                });
            }
        }
    }
    $("#autoId_all").change(function() {
        $('.deleteAllRecord').attr('checked', 'checked');
        var idList = $(".deleteAllRecord:checked").serialize();
        if (idList) {
            if (confirm("Are you sure want to delete?")) {
                $.post("<?php echo Yii::app()->createUrl("classes/deleteClassImage"); ?>", idList, function(response) {
                    location.reload('#classImage-id');
                });
            }
        }
        $('.deleteAllRecord').removeAttr('checked');

    })


</script>


